# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

inherit eutils cmake-utils confutils flag-o-matic
MY_PN="${PN/qutim-/}"
MY_PN1="${PN/-jabber/}"

DESCRIPTION="Jabber protocol plugin for net-im/qutim"
HOMEPAGE="http://www.qutim.org"
LICENSE="GPL-2"
SRC_URI="http://www.qutim.org/uploads/src/qutim-0.2.0.tar.bz2"

SLOT="0.2"
KEYWORDS="~amd64 ~ppc ~ppc64 ~x86"
IUSE="openssl +gnutls +gloox-static debug"

RDEPEND="net-im/qutim:0.2
	!gloox-static? ( >=net-libs/gloox-0.9.9.5 )
	sys-libs/zlib
	net-dns/libidn
	openssl? ( dev-libs/openssl )
	gnutls? ( net-libs/gnutls )"

DEPEND="${RDEPEND}
	>=dev-util/cmake-2.6
	!x11-plugins/qutim-jabber:live"

RESTRICT="debug? ( strip )"

S=${WORKDIR}/qutim-0.2.0/plugins/${MY_PN}

pkg_setup()
{
	confutils_use_conflict gnutls openssl
	if ! (use gloox-static) && (use gnutls) ; then
		confutils_require_built_with_any net-libs/gloox gnutls
	fi
}

src_prepare()
{
	if (use debug) ; then
		unset CFLAGS CXXFLAGS
		append-flags -O1 -g -ggdb
		CMAKE_BUILD_TYPE="debug"
	fi

	mycmakeargs="-DWinTLS=0 -DCMAKE_INSTALL_PREFIX=/usr -DUNIX=1 -WIN32=0 -DAPPLE=0"
	if (use openssl) ; then
		mycmakeargs="${mycmakeargs} -DOpenSSL=1 -DGNUTLS=0"
	fi

	if (use gnutls) ; then
		mycmakeargs="${mycmakeargs} -DOpenSSL=0 -DGNUTLS=1"
        fi

	if (use gloox-static) ; then
		mycmakeargs="${mycmakeargs} -DGLOOX_SHARED=0"
	else
		mycmakeargs="${mycmakeargs} -DGLOOX_SHARED=1"
	fi

	CMAKE_IN_SOURCE_BUILD=1

	# Меняем путь установки либ
	sed -i "/DESTINATION/s/lib/$(get_libdir)/g" ${S}/CMakeLists.txt
}

src_install()
{
	cmake-utils_src_install

	into /usr
	dodir /usr/include/qutim
	cp ${S}/include/${MY_PN1}/*h ${D}/usr/include/${MY_PN1}/ || die "Failed to install headers"
}

